package drds.common.db.xml_mapping.parameter_and_result_value_type;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


public class BigIntegerTypeHandler extends BaseTypeHandler<BigInteger> {

  @Override
  public void setNonNullParameter(PreparedStatement preparedStatement, int index, BigInteger parameter, JdbcType jdbcType) throws SQLException {
    preparedStatement.setBigDecimal(index, new BigDecimal(parameter));
  }

  @Override
  public BigInteger getNullableResult(ResultSet resultSet, String columnName) throws SQLException {
    BigDecimal bigDecimal = resultSet.getBigDecimal(columnName);
    return bigDecimal == null ? null : bigDecimal.toBigInteger();
  }

  @Override
  public BigInteger getNullableResult(ResultSet resultSet, int columnIndex) throws SQLException {
    BigDecimal bigDecimal = resultSet.getBigDecimal(columnIndex);
    return bigDecimal == null ? null : bigDecimal.toBigInteger();
  }


}
